(() => {

    console.log('我又变帅了')

    // 接口是对象状态（属性）和行为（方法）的抽象
    // 是一种对类型的约束
    interface IPerson {
        readonly id: number // 只读
        name: string
        age: number
        sex?: string // 可选属性
    }

    const person: IPerson = {
        id: 1,
        name: 'yejing',
        age: 34,
        sex: '女'
    }

    interface Card {
        suit: string;
        card: number;
    }

    interface Deck {
        suits: string[];
        cards: number[];
        createCardPicker(this: Deck): () => Card; // 返回一个函数，函数的返回值是Card的一个对象
    }

    let deck: Deck = {
        suits: ["hearts", "spades", "clubs", "diamonds"],
        cards: Array(52),
        // NOTE: The function now explicitly specifies that its callee must be of type Deck
        createCardPicker: function (this: Deck) {
            return () => {
                let pickedCard = Math.floor(Math.random() * 52);
                let pickedSuit = Math.floor(pickedCard / 13);
                return { suit: this.suits[pickedSuit], card: pickedCard % 13 };
            }
        }
    }

    let cardPicker = deck.createCardPicker();
    let pickedCard = cardPicker();

    alert("card: " + pickedCard.card + " of " + pickedCard.suit);


})()